package com.xysq.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.xysq.lemon.R;
import com.xysq.util.WheelView;

import java.util.Arrays;

import butterknife.InjectView;

/**
 * @Author huangdongkai
 * webview测试类，用来从html跳转到activity
 */

public class WheelViewActivity extends BaseActivity implements View.OnClickListener {
    @InjectView(R.id.wv_school)
    WheelView schoolWv;
    private String[] PLANETS;
    private int[] PLANETS_ID;
    private int position;
    private String[] dateArray;
    public static final String DATAS = "datas";
    public static final String IDS = "ids";
    public static final String DATE_IDENT = "date_flag";
    public static final String POSITION = "position";
    public static final String NAME = "name";
    public static final String ID = "id";
    public static final String FLAG = "flag";
    public static final int CODE = 1;
    public static final int DATE = 5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);//去除title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_wheel_view);
        initView();
        getData();
    }

    private void initView() {
    }

    private void getData() {
        String flag = getIntent().getStringExtra(FLAG);
        if (flag.equals(UserActivity.flagSchool)) {//
            PLANETS = getIntent().getStringArrayExtra(DATAS);
            PLANETS_ID = getIntent().getIntArrayExtra(IDS);
            position = getIntent().getIntExtra(POSITION, 0);
            schoolWv.setOffset(1);
            schoolWv.setItems(Arrays.asList(PLANETS));
            schoolWv.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
                @Override
                public void onSelected(TextView item, int selectedIndex) {
                    Intent intent = new Intent();
                    intent.putExtra(NAME, item.getText().toString());
                    intent.putExtra(ID, PLANETS_ID[selectedIndex - 1]);
                    setResult(CODE, intent);
                    finish();
                }
            });
        }
        if(flag.equals(UserActivity.flagDate)){
            dateArray = getIntent().getStringArrayExtra(DATE_IDENT);
            schoolWv.setOffset(dateArray.length);
            schoolWv.setItems(Arrays.asList(dateArray));
            schoolWv.setOnWheelViewListener(new WheelView.OnWheelViewListener(){
                @Override
                public void onSelected(TextView item, int selectedIndex) {
                    super.onSelected(item, selectedIndex);
                    Intent intent = new Intent();
                    intent.putExtra(DATE_IDENT, item.getText().toString());
                    setResult(DATE, intent);
                    finish();
                }
            });
        }
    }

    @Override
    public void onClick(View view) {
    }
}
